Cocos2d-x v3 invalid conversion from 'cocos2d::Layer* [on hold]

Posted by Hammerh5 on Game Development See other posts from Game Development or by Hammerh5
Published on 2014-06-03T23:27:29Z Indexed on 2014/06/04 3:41 UTC
Read the original article Hit count: 584

Filed under:
|
|

Hello guys I'm learning cocos2d-x v3 right but most of the code that I can find is to the version 2.

My specific error is this one, when I try to compile my cocos2s-x 3 project this error shows.

invalid conversion from 'cocos2d::Layer to Game* [-fpermisive]*

What I want to do is create a new game scene in the following code:

//Game.cpp
#include "Game.h"

Scene* Game::scene()
{
scene *sc = CCScene::create();
sc->setTag(TAG_GAME_SCENE);
const Game *g = Game::create(); //Here is where the conversions fails.
sc->addChild(g, 0, TAG_GAME_LAYER);

return sc;
}

Of course this is my header file

//Game.h
#include "cocos2d.h"
#include "Mole.h"
#include "AppDelegate.h"

using namespace cocos2d;

class Game: public cocos2d::Layer {
cocos2d::CCArray *moles;
float timeBetweenMoles, timeElapsed, increaseMolesAtTime, increaseElapsed,
        lastMoleHiTime;

int molesAtOnce;
cocos2d::CCSize s;
bool isPaused;
    public:
CCString *missSound, *hitSound;
static cocos2d::Scene* scene();

    virtual bool init();
void showMole();
void initializeGame();
void onEnterTransitionDidFinish();
void onExit();
void onTouchesBegan(const std::vector<cocos2d::Touch *> &touches,
        cocos2d::Event *event); 
void tick(float dt);
cocos2d::CCArray* getMoles(bool isUp);

//LAYER_CREATE_FUNC(Game);
}; 
#endif /* GAME_H_ */

I don't know what's wrong I suppose this code works fine in Cocos2d-x v2. It's maybe some changes in the C++ version ?

© Game Development or respective owner

Related posts about c++

Related posts about cocos2d-x